<%@include  file="/WEB-INF/header.jsp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<script>
//删除场地信息
function delPlace(placename){
	if(confirm("是否删除该场地信息?")){
	//ajax异步请求，三个参数，第一个地址,第二个控制层username、页面的username，第三个参数function函数
	$.post("${pageContext.request.contextPath}/place/delPlace.action",{"placename":placename},
	//回调函数，得到的是json格式，controller层
		function(data){
	            if(data =="OK"){
	                alert("删除场地信息成功");
	                window.location.reload();
	            }else{
	                alert("删除场地信息失败");
	                window.location.reload();
	            }
	        });
	    }
	}
	
	
	
//新建场地
function createPlace() {
	if($("#new_placeName").val() == null || $("#new_placeName").val() == ''){
		alert("场地名称不能为空");	
		return;
	}
	if($("#new_placeAddress").val() == '' || $("#new_placeAddress").val() == null){
		alert("场地地址不能为空")
		return;
	}
	$.post("${pageContext.request.contextPath}/place/create.action",
			
	$("#new_place_form").serialize(),function(data){
	        if(data =="OK"){
	            alert("添加场地成功");
	            window.location.reload();
	        }else{
	            alert("添加场地失败");
	            window.location.reload();
	        }       
    });

}


//通过id获取修改的书籍信息
function editPlace(id) {
	  $.ajax({
	        type:"get",
	        url:"<%=basePath%>place/getPlaceById.action",
	        data:{"place_id":id},
	        success:function(data) {
	        	$("#edit_place_id").val(data.id);
	            $("#edit_placeName").val(data.name);
	            $("#edit_placeAddress").val(data.address);
	            $("#edit_placeSubject").val(data.subject);
	            $("#edit_placeCategory").val(data.category);
	            
	           
	        }
	    });
}

function updatePlace() {
	
	$.post("${pageContext.request.contextPath}/place/update.action",$("#edit_place_form").serialize(),function(data){
		if(data =="OK"){
			alert("修改场地信息成功");
			window.location.reload();
		}else{
			alert("修改场地信息失败");
			window.location.reload();
		}
	});
}


</script>
<div id="page-wrapper">
	 <div class="row">
			<div class="col-lg-12">
				<h1 class="page-header">场地管理</h1>
			</div>
	</div>
	<div class="panel panel-default">
		<div class="panel-body">
			<form class="form-inline" method="get" style="float:left"  
			      action="${pageContext.request.contextPath }/place/findplace.action">
				<div class="form-group">
					<label for="placeName">查询场地信息</label>
					&nbsp;&nbsp; 
					<input type="text" class="form-control" id="name" 
					                   value="${name}" name="name" />
				
				</div>
				&nbsp;&nbsp;
				<button type="submit" class="btn btn-success">查询</button>
			</form>
			
			<form class="form-inline" style="float:left" 
			      action="${pageContext.request.contextPath }/place/getAllplace.action">
			      &nbsp;&nbsp;
				   <button type="submit" class="btn btn-warning">返回</button>
			</form>
			
			
			
		</div>
	</div>
	
	
	<table class="table table-striped">
	<caption><a href="#" class="btn btn-info" data-toggle="modal" data-target="#newPlaceDialog">添加场地信息</a></caption>
	
	

	<thead>
    <tr>
      <th>场地名称</th>
      <th>场地位置</th>
      <th>科目</th>
      <th>场地种类</th>
	  <th>操作</th>
   
    </tr>
  </thead>
  <tbody>
    <c:forEach items="${Place_list}" var="p">
      <tr>
      <td>${p.name}</td>
      <td>${p.address}</td>
      <td>${p.subject}</td>
      <td>${p.category == 0?'考场':p.category == 1?'训练场':'训练场/考场'}</td>
      <td>
	   <a href="#" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#placeEditDialog" onclick= "editPlace(${p.id})">修改</a>
	   	<a href="#" class="btn btn-danger btn-xs" onclick="delPlace('${p.name}')">删除</a>
		      <!-- 按钮增加 /onlinck事件，方法名(参数为字符串需用'') -> js脚本 -->
	 </td>
      	
      
    </tr>
  </c:forEach>


  </tbody>
  </table>
</div>
<!-- 创建课程信息模态框 -->
<div class="modal fade" id="newPlaceDialog" data-backdrop="static" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">新建场地信息</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal" id="new_place_form">
                    <input type="hidden" id="new_place_id" name="id"/>
					<div class="form-group" id="form_user">
						<label for="new_placeName" style="float:left;padding:7px 15px 0 27px;">场地名称</label> 
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_placeName" placeholder="场地名称" name="name" />
						</div>
					</div>					
					<div class="form-group" id="form_user">
						<label for="new_placeAddress" style="float:left;padding:7px 15px 0 27px;">场地地址</label> 
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_placeAddress" placeholder="场地地址" name="address" />
						</div>
					</div>
					<div class="form-group" id="form_user">
						<label for="new_placeSubject" style="float:left;padding:7px 15px 0 27px;">考场科目</label> 
						<div class="col-sm-10">
							<select	class="form-control" id="new_placeSubject" name="subject">
								<option value ="科目一" selected>
								科目一						
								</option>
								<option value="科目二" >
								科目二								
								</option>
								<option value="科目三" >
								科目三								
								</option>
								<option value="科目四" >
								科目四							
								</option>
							</select>
						</div>
					</div>
					<div class="form-group" id="form_user">
						<label for="new_placeSubject" style="float:left;padding:7px 15px 0 27px;">考场科目</label> 
						<div class="col-sm-10">
							<select	class="form-control" id="new_placeCategory" name="category">
								<option value ="0" selected>
								考场					
								</option>
								<option value="1" >
								训练场								
								</option>
								<option value="2" >
								考场	/训练场								
								</option>
							</select>
						</div>
					</div>								
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-success" onclick="createPlace()">添加场地</button>
			</div>
		</div>
	</div>
</div>
<!-- 修改课程信息模态框 -->
<div class="modal fade" id="placeEditDialog" data-backdrop="static" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">修改场地基本信息</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal" id="edit_place_form">
                    <input type="hidden" id="edit_place_id" name="id"/>
					<div class="form-group" id="form_user">
						<label for="edit_placeName" style="float:left;padding:7px 15px 0 27px;">场地名称</label> 
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_placeName" placeholder="场地名称" name="name" required/>
						</div>
					</div>
					<div class="form-group" id="form_user">
						<label for="edit_placeAddress" style="float:left;padding:7px 15px 0 27px;">场地地址</label> 
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_placeAddress" placeholder="场地地址" name="address" required/>
						</div>
					</div>
					<div class="form-group" id="form_user">
						<label for="edit_placeSubject" style="float:left;padding:7px 15px 0 27px;">场地类别</label> 
						<div class="col-sm-10">
							<select	class="form-control" id="edit_placeSubject" name="subject">
								<option value ="科目一" selected>
								科目一						
								</option>
								<option value="科目二" >
								科目二								
								</option>
								<option value="科目三" >
								科目三								
								</option>
								<option value="科目四" >
								科目四							
								</option>
							</select>
						</div>
					</div>
					<div class="form-group" id="form_user">
						<label for="edit_placeSubject" style="float:left;padding:7px 15px 0 27px;">考场科目</label> 
						<div class="col-sm-10">
							<select	class="form-control" id="edit_placeCategory" name="category">
								<option value ="0" selected>
								考场					
								</option>
								<option value="1" >
								训练场								
								</option>
								<option value="2" >
								考场	/训练场								
								</option>
							</select>
						</div>
					</div>	
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-success" onclick="updatePlace()">修改场地</button>
			</div>
		</div>
	</div>
	
</div>


<%@include  file="/WEB-INF/footer.jsp"%>